/* $RCSFile: Register.aspx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice/Secure/Register.aspx.cs $
 * $log$
 * Revision 20 2010/08/09 10:51:22  christian.surieux
 *   Added Log comment to all .aspx .ascx .master files
 * Revision 19 2010/08/09 09:44:01  christian.surieux
 *   Added Log to cs sources files
 * Revision 6 2010/08/06 19:56:26  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

using Trace2    =   System.Diagnostics.Trace;

using AddonNice;
using AddonNice.UI;
using AddonNice.UI.WebControls;
using AddonNice.Core;
using AddonNice.Configuration;
using AddonNice.Diagnostics;
using AddonNice.Authentication;
using AddonNice.Security;
using AddonNice.Settings;
using AddonNice.CRMWrapper;
using AddonNice.Helpers;

namespace AddonNice.Secure
{
    public partial class Register : StaticCRMPage
    {
        // Must be const RegisterPageID
        public override int PageID
		{
			get
			{   return StStr.RegisterPageID; }
		}

        protected void Page_Load(object sender, EventArgs e)
        {
    		if (PageTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Register Page_Load BEG at : {0}, IsPostBack: {1}",DateTime.UtcNow,IsPostBack),PageTraceSwitch.Sw.Info);
			if(!bool.Parse(portalSettings.CustomSettings[StStr.SiteAllowNewRegistration].Value))
				PortalSecurity.PortalHome(true,this);
    		if (PageTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Register Page_Load END at : {0}",DateTime.UtcNow),PageTraceSwitch.Sw.Info);
        }

        /// <summary>
        /// We changed the normal order, the pagelayout is loaded in PreInit to get skins
		/// and have opportunity to load modules in OnPreInit,  having correct theming
		/// Page_Load event is just here in cas we want statistics
        /// </summary>
		protected override void OnPreInit(EventArgs e)
        {
            // Ensure that the visiting user has access to the current page
            bool Ok     =   AddonNice.Security.PortalSecurity.IsUserInRoles(portalSettings.ActivePageSettings.AuthorizedRoles);
    		if (PageTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]Register OnPreInit BEG Ok: {0}",Ok),PageTraceSwitch.Sw.Info);
            if ( !Ok )
                PortalSecurity.AccessDenied();
            TPans.InitPanes(this);
            base.OnPreInit(e);
    		if (PageTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine("[V]Register OnPreInit END",PageTraceSwitch.Sw.Info);
        }

        protected override void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(Page_Load);
        }
    }
}
